package com.xxh.user.mq;

import com.xxh.user.service.EmailService;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.io.IOException;

//@RabbitListener(queues = MqConfig.EmailQUEUE)
@Slf4j
@Component
public class EmailHandler {

    @Resource
    EmailService emailService;

    @RabbitHandler
    public void HandlerSendEmail(PostMessage message){
        log.info("发送邮件");
        try {
            emailService.sendEmail(message.getUser());
        } catch (MessagingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        }finally {
            log.info("邮件发送完成");
        }
    }
}
